/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：InnerChestScreen.java <br>
 * 创建时间：2015-1-19 上午10:37:25 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.expand;

import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.HashMap;

import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.data.Item;
import lostland.gmud.exv2.data.MainChar;
import lostland.gmud.exv2.ui.SimpleNotificationScreen;

/**
 * 类名：InnerChestScreen <br>
 * 说明：宝箱里界面
 *
 * @author 12548
 */
public class InnerChestScreen extends GeneralMenuScreen {

	boolean getin;
	HashMap<String, Item> s;
	static ArrayList<String> ss;

	/**
	 * @param s
	 * @param title
	 */
	public InnerChestScreen(HashMap<String, Item> s, boolean getin) {
		super(gets(s), "请选择要存取的物品");
		this.s = s;
		this.getin = getin;
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ScrollableMenuScreen#onCancel()
	 */
	@Override
	public void onCancel() {
		getGame().popScreen();
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ScrollableMenuScreen#onClick(int)
	 */
	@Override
	public void onClick(int i) {
		MainChar from, to;
		if (getin) {
			from = Gmud.mc;
			to = getGame().data.chest;
		} else {
			from = getGame().data.chest;
			to = Gmud.mc;
		}

		Item itm = s.get(ss.get(i));

		if (!Item.notNull(itm)) {
			Logger.e("宝箱存取失败！");
			return;
		}

		if (!from.only(itm)) {
			if (to.give(itm)) {
				from.drop(itm);
				getGame().popScreen();
			} else {
				new SimpleNotificationScreen("物品栏或储物箱已满或堆叠已满！").pushToGame();
			}
		} else {
			new SimpleNotificationScreen("已装备的物品无法移出！").pushToGame();
		}
	}

	static ArrayList<String> gets(HashMap<String, Item> s) {
		ArrayList<String> t = new ArrayList<>();
		for (String i : s.keySet()) {
			t.add(i);
		}
		ss = t;
		return t;
	}

}
